/**
 * LEKU APPLIANCE CHAINS.
 * Copyright (c) 2016-2016 All Rights Reserved.
 */
package com.leku.video.service.util;

import com.leku.commons.util.DateUtil;
import com.leku.commons.util.StringUtil;
import com.leku.video.dto.result.video.VideoUrlDto;

/**
 * 功能描述: 处理地址加密
 *
 * @author Ranphy
 * @created 2018年8月8日
 * @version 1.0.0
 */
public class DealUrlUtil {

	/**
	 * 
	 * 功能描述:处理地址加密
	 *
	 * @param url
	 * @return
	 * @see [相关类/方法](可选)
	 * @since [产品/模块版本](可选)
	 */
	public static VideoUrlDto dealUrl(VideoUrlDto url) {

		// 加密人人视频地址
		if ("网络r".equals(url.getSite())) {
			if (url.getUrl().startsWith("bk123")) {
				String key = DateUtil.currentDay() + "fkbaoyun";
				String nowurl = EncodeUrlUtil.encodeDes(url.getUrl().replace("bk123://", ""), key);
				String urlinfo = "bk123://" + nowurl;
				url.setUrl(urlinfo);
			} else {
				String rrAddr = EncodeUrlUtil.encodeDes(url.getUrl(), "8888888888888888");
				url.setUrl("zcby://" + rrAddr);
			}
			url.setOriginUrl(null);
		}

		// 加密97泰剧地址
		if (url.getUrl().contains("www.97taiju.com") || url.getUrl().contains("kkk.hanjucc.com")) {
			String htAddr = EncodeUrlUtil.encodeHTTV(url.getUrl());
			url.setUrl(htAddr);
			url.setOriginUrl(null);
		}

		// 加密mp4地址
		if ((url.getUrl().startsWith("lkvideo") || url.getUrl().startsWith("MP4://")) && url.getUrl().endsWith("mp4")) {
			String nowurl = EncodeUrlUtil.encodeDateDes(url.getUrl(), "baoyunfk");
			String urlinfo = "mbby://" + nowurl;
			url.setUrl(urlinfo);
			url.setOriginUrl(null);
		}

		// 加密韩剧大全地址
		if (url.getUrl().startsWith("by123")) {
			String key = DateUtil.currentDay() + "fkbaoyun";
			String nowurl = EncodeUrlUtil.encodeDes(url.getUrl().replace("by123://", ""), key);
			String urlinfo = "by123://" + nowurl;
			url.setUrl(urlinfo);
			url.setOriginUrl(null);
		}

		// 加密西瓜地址
		if (url.getUrl().startsWith("ixigua://")) {
			String key = "kuafuzhuirinibia";
			String nowurl = EncodeUrlUtil.encodeDes(url.getUrl(), key);
			String urlinfo = "K88://" + nowurl;
			url.setUrl(urlinfo);
			url.setOriginUrl(null);
		}

		// 加密蚂蚁视频地址
		if ("网络my".equals(url.getSite())) {
			String nowurl = EncodeUrlUtil.encodeDes(url.getUrl(), DateUtil.currentDay(DateUtil.FOMAT_YMD) + "lekufans");
			String urlinfo = "lekufans://" + nowurl;
			url.setUrl(urlinfo);
			url.setOriginUrl(null);
		}

		// 加密麻花视频地址
		if ("网络mh".equals(url.getSite())) {
			String key = DateUtil.currentDay(DateUtil.FOMAT_YMD) + "mhkufans";
			String nowurl = EncodeUrlUtil.encodeDes(url.getUrl().replace("mh://", ""), key);
			String urlinfo = "mh://" + nowurl;
			url.setUrl(urlinfo);
			url.setOriginUrl(null);
		}

		// 加密私享范特西
		if (url.getUrl().contains("self.fantasy.tv")) {
			String nowurl = EncodeUrlUtil.encodeDes(url.getUrl(), "fantasyforlktech");
			String urlinfo = "douyin://" + nowurl;
			url.setUrl(urlinfo);
			url.setOriginUrl(null);
		}

		// 加密百度盘
		if (url.getUrl().startsWith("pan://")) {
			String subUrl = url.getUrl().substring(6, url.getUrl().length());
			url.setUrl("pan://" + StringUtil.encodeBase64(subUrl));
			url.setOriginUrl(null);
		}

		// 加密ppbox地址
		if (url.getUrl().contains("type=ppbox.launcher") || url.getUrl().contains("phone.android.download")) {
			String nowurl = EncodeUrlUtil.encodeDateDes(url.getUrl(), "baoyunfk");
			String urlinfo = "wrby://" + nowurl;
			url.setUrl(urlinfo);
			url.setOriginUrl(null);
		}

		if (url.getUrl().startsWith("SS")) {
			url.setOriginUrl(null);
		}

		return url;
	}
}
